// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_detail_info = require("../financing/financingDetailInfo.css");
	var css_detail_info1 = require("../main/financingDetailInfo.css");
	var constant = require("constant");
	var storage = window.sessionStorage;
	var tools = require("tools");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var financeId = "";
	var enterpriseId = "";
	var financeType = "";
	var financeNumber = "";
	var dataFinancingDetail;
	var financeState;
	var init = function(page) {
		$(".d2").css("background", "url(../../../res/png/tab_bg2.png) no-repeat bottom");
		financeId = page.params.financeId || base.getUrlParam("financeId");
		initEvent();
		initFinancingDetail(financeId);
		router.init();
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}

		//点击首页
		$(".platform_main").unbind("click").click(function() {
			top.location.href = "../main/platform_main.html";
		});
		//待审批列表
		$(".financeApproveList").unbind("click").click(function() {
			router.route("main/main_finance.html?left=0&financeState=1", true);
		});

		//点击融资申请基本信息
		$(".financeDetailInfo").on("click", function() {
			router.route("main/financingDetailInfo.html?financeId=" + financeId, true);
		});
		//点击证明材料
		$(".evidentiaryCategorys").on("click", function() {
			router.route("main/financingDetailEvidentiaryCategorys.html?financeId=" + financeId, true);
		});
		//点击融资评审
		$(".financingDetailDynamic").on("click", function() {
			router.route("main/financeApprove.html?left=0&financeState=1&financeId=" + financeId, true);
		});

		$("#financingDetailInfo").on("click", ".enterpriseDetail", function() {
			storage.setItem("enterpriseId", enterpriseId);
			window.open("../client/clientManageDetailIntact.html");
		});

	};

	var initFinancingDetail = function(financeId) {
		base.fnAjax({
			action: "inquireFinanceApplicationDetail.json",
			async: false,
			oData: {
				financeId: financeId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					juicer.register("getValueByKey", constant.getValueByKey);
					juicer.register("formatCurrency", tools.formatCurrency);
					var html;
					dataFinancingDetail = data;
					var financingDetailData = data.datas[0];
					enterpriseId = financingDetailData.enterpriseId;
					var financingDetail = $("#financingDetail").html();
					if (financingDetail != undefined) {
						html = juicer(financingDetail, data);
					}
					$(".tab1").html(html);
					financeType = financingDetailData.financeType;
					financeNumber = financingDetailData.financeNumber;
					financeState = financingDetailData.financeState;
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});

	}


	return {
		init: init
	};
});